package ru.urfc.portal.managers.impl;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import ru.urfc.portal.managers.BaseManager;
import ru.urfc.portal.managers.NotificationManager;
import ru.urfc.portal.model.NotificationSettings;

@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class NotificationManagerImpl extends BaseManager implements NotificationManager {
	
	@Override
	public NotificationSettings getGlobal() {
		return exactlyOne(find(NotificationSettings.class, "global", true));
	}

	@Override
	public NotificationSettings getSettings(Long clientId) {
		return exactlyOne(find(NotificationSettings.class, "client.id", clientId));
	}

	@Override
	public NotificationSettings updateGlobalSettings(NotificationSettings settings) {
		return getGlobal().updateAsGlobalSettings(settings);
	}
	
	@Override
	public NotificationSettings updateClientSettings(Long clientId, NotificationSettings settings) {
		return getSettings(clientId).updateAsClientSettings(settings);
	}	
}
